{ "cells": [ { "cell_type": "markdown", "id": "31e14143", "metadata": {}, "source": [ "## Reverse a list" ] }, { "cell_type": "code", "execution_count": 6, "id": "4fd8fcaa", "metadata": {}, "outputs": [], "source": [ "names=['Sahil','Sonia','Sourav']\n", "age=[10,20,30]" ] }, { "cell_type": "markdown", "id": "6426c14e", "metadata": {}, "source": [ "#1 Using inbuilt method" ] }, { "cell_type": "code", "execution_count": 7, "id": "44710703", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Sourav', 'Sonia', 'Sahil']" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "names.reverse()\n", "names" ] }, { "cell_type": "markdown", "id": "43afb82b", "metadata": {}, "source": [ "#2 Using slicing" ] }, { "cell_type": "code", "execution_count": 8, "id": "449fd699", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Sahil', 'Sonia', 'Sourav']" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "names[::-1]" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.8" } }, "nbformat": 4, "nbformat_minor": 5 }